﻿// ResizeArea.qml
import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    id: resizeArea
    anchors.fill: parent

    property var window
    property var windowsNative

    // 边缘调整大小区域
    property int resizeBorderWidth: 5

    // 左上角
    MouseArea {
        width: resizeBorderWidth
        height: resizeBorderWidth
        anchors.top: parent.top
        anchors.left: parent.left
        cursorShape: Qt.SizeFDiagCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.TopEdge | Qt.LeftEdge)
        }
    }

    // 上边缘
    MouseArea {
        height: resizeBorderWidth
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.leftMargin: resizeBorderWidth
        anchors.rightMargin: resizeBorderWidth
        cursorShape: Qt.SizeVerCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.TopEdge)
        }
    }

    // 右上角
    MouseArea {
        width: resizeBorderWidth
        height: resizeBorderWidth
        anchors.top: parent.top
        anchors.right: parent.right
        cursorShape: Qt.SizeBDiagCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.TopEdge | Qt.RightEdge)
        }
    }

    // 右边缘
    MouseArea {
        width: resizeBorderWidth
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        anchors.topMargin: resizeBorderWidth
        anchors.bottomMargin: resizeBorderWidth
        cursorShape: Qt.SizeHorCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.RightEdge)
        }
    }

    // 右下角
    MouseArea {
        width: resizeBorderWidth
        height: resizeBorderWidth
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        cursorShape: Qt.SizeFDiagCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.BottomEdge | Qt.RightEdge)
        }
    }

    // 下边缘
    MouseArea {
        height: resizeBorderWidth
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.leftMargin: resizeBorderWidth
        anchors.rightMargin: resizeBorderWidth
        cursorShape: Qt.SizeVerCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.BottomEdge)
        }
    }

    // 左下角
    MouseArea {
        width: resizeBorderWidth
        height: resizeBorderWidth
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        cursorShape: Qt.SizeBDiagCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.BottomEdge | Qt.LeftEdge)
        }
    }

    // 左边缘
    MouseArea {
        width: resizeBorderWidth
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.topMargin: resizeBorderWidth
        anchors.bottomMargin: resizeBorderWidth
        cursorShape: Qt.SizeHorCursor

        onPressed: {
            windowsNative.startSystemResize(window, Qt.point(mouse.x, mouse.y), Qt.LeftEdge)
        }
    }
}
